package org.liuhy.jbpm4.property
{
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.containers.Canvas;
	import mx.containers.HBox;
	import mx.containers.VBox;
	import mx.controls.ComboBox;
	import mx.controls.Label;
	import mx.controls.TextInput;
	import mx.events.FlexEvent;
	
	import org.liuhy.jbpm4.TaskFlowNode;
	
	public class TaskProperty extends Canvas
	{
		private var _flowNode:TaskFlowNode=null;
		private var _lblTitle:Label = new Label;
		public var _txtTitle:TextInput = new TextInput;
		
		private var _lblTaskType:Label = new Label;
		public var _cboxTaskType:ComboBox = new ComboBox();
		
		private var _lblExpr:Label = new Label;
		public var _txtExpr:TextInput = new TextInput;
		
		private var _lblForm:Label = new Label;
		public var _txtForm:TextInput = new TextInput;
		 
		[Bindable]
		public var _taskTypeArray:ArrayCollection = new ArrayCollection(
		    [ 
		    	{label:"none", code:"none"},
		    	{label:"assignee", code:"assignee"},
		        {label:"candidate-groups", code:"candidate-groups"},
		        {label:"candidate-users", code:"candidate-users"}, 
		        {label:"swimlane", code:"swimlane"}
		      ]);

		public function TaskProperty(p_flowNode:TaskFlowNode)
		{
			
			this._flowNode = p_flowNode;
			this._txtTitle.addEventListener(FlexEvent.PREINITIALIZE,function(event:FlexEvent):void{
				BindingUtils.bindProperty(_txtTitle,"text",_flowNode._textArea,"text");
			});
//			
			var _hbox:HBox = new HBox();			
			this._lblTitle.text = "Name         ";
			this._txtTitle.width= 200;
			_hbox.addChild(_lblTitle);
			_hbox.addChild(this._txtTitle);
			
			var _hbox1:HBox = new HBox();			
			_lblTaskType.text = "Type		";
			this._cboxTaskType.dataProvider = this._taskTypeArray;
			_hbox1.addChild(_lblTaskType);
			_hbox1.addChild(this._cboxTaskType);
			
			var _hbox2:HBox = new HBox();			
			_lblExpr.text = "Expression";
			_txtExpr.width = 200;
			_hbox2.addChild(_lblExpr);
			_hbox2.addChild(_txtExpr);
			
			var _hbox3:HBox = new HBox();			
			_lblForm.text = "Form		";
			_txtForm.width = 200;
			_hbox3.addChild(_lblForm);
			_hbox3.addChild(_txtForm);			
			
			var _vbox:VBox = new VBox();
			_vbox.addChild(_hbox);
			_vbox.addChild(_hbox1);
			_vbox.addChild(_hbox2);
			_vbox.addChild(_hbox3);
			this.addChild(_vbox);
		}
		public function get title():String{
			return _txtTitle.text;
		}
		public function set title(p_title:String):void{
			_txtTitle.text = p_title;
		}
		public function get expr():String{
			return _txtExpr.text;
		}
		public function set expr(p_expr:String):void{
			_txtExpr.text = p_expr;
		}
		public function get taskType():String{
			return this._cboxTaskType.selectedItem.label;
		}
		public function set taskType(p_taskType:String):void{
			_cboxTaskType.selectedItem = p_taskType;
		}
		public function get form():String{
			return this._txtForm.text;
		}
		public function set form(p_form:String):void{
			_txtForm.text = p_form;
		}
	}
}